home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Presentations / Presentations ’96 / Sessions ’96 / Advanced Memory Mgmt / alloc_gla.c1.0.10 / alloc_gla.c Read Me next >
Encoding:
Text File  |  1996-06-17  |  6.6 KB  |  166 lines  |  [TEXT/KAHL]

  1. alloc_gla.c Read Me
  2. -------------------
  3.  
  4. This file is a replacement for the current alloc.c, and replaces the routines 
  5. malloc, realloc, calloc, and free with a new version which (1) validates its 
  6. zone(s) on calls to its routines, (2) is application-configurable to return 
  7. memory zones to the Macintosh application heap when they are freed, (3) has an 
  8. application-configurable "crossover" size, where memory requests larger than a 
  9. certain size allocate a zone to that single memory request.  Also, it is 
  10. written in straight C, rather than a mixture of C and 68K assembly. It is also 
  11. faster during malloc than the current version.
  12.  
  13. The biggest advantages to this version are its heap validation and its
  14. alignment of blocks on an 8-byte boundary, which has HUGE benefits when working
  15. with doubles on a PowerPC (and helps the 68K processor as well).  When NDEBUG is 
  16. not defined, it verifies that valid values are in its zone header and memory 
  17. block entries.  When freeing memory, it validates that the beginning of the 
  18. next block hasn't been overwritten.
  19.  
  20. How to use
  21. ----------
  22.  
  23. I now provide an AppleScript application which will open the appropriate ANSI
  24. libraries for both TPM and SPM and update them to use alloc_gla.c instead of
  25. alloc.c.
  26.  
  27. You will still need to update your projects to use the new ANSI libraries.
  28.  
  29. Description and New Information
  30. -------------------------------
  31.  
  32. This code uses a series of linked memory "zones", which are then suballocated 
  33. to reduce the demands on the Macintosh Memory manager for small memory 
  34. allocation requests.
  35.  
  36. There are two global variables which allow you to configure the behavior of 
  37. the new alloc.c.  These global variables are:
  38.  
  39. unsigned long gMaxBlockSize    This configures the "crossover" size for the 
  40.                             application.  By default, this value is set to 
  41.                             32768, which means that memory requests smaller 
  42.                             than this size will be sub-allocated from a 
  43.                             gMaxBlockSize zone.  Requests larger than 
  44.                             gMaxBlockSize will be allocated from their own 
  45.                             zone.
  46.  
  47. Boolean gRestoreMemToHeap    This flag configures the behavior of the free 
  48.                             routine to return freed memory zones back to the 
  49.                             Macintosh Memory manager.  By default, this flag 
  50.                             is set to true so that freed zones will be 
  51.                             returned to the application heap.
  52.  
  53. There are also two new routines for preallocating and cleaning up freed zones.  
  54. This allows you to specify a pool of non-relocatable memory at application 
  55. start which can be used for objects and memory requests.  These two routines 
  56. are:
  57.  
  58. void *prealloc(size_t size)    This routine will allocate a zone large enough 
  59.                             to satisfy a memory request for size bytes.  You 
  60.                             can use this to preallocate non-relocatable 
  61.                             memory for use by your application and document 
  62.                             objects.
  63.  
  64. void cleanupalloc(void)        This routine will return to the application heap 
  65.                             all zones which have no memory suballocated out 
  66.                             of them.
  67.  
  68. There is also a debugging routine which is available to your application if 
  69. you define the compile-time flag __DUMPBLOCKS__ to 1.  The routine:
  70.  
  71.     Boolean DumpBlocks(void)
  72.  
  73. will then become available and will display the current contents of the memory 
  74. zone(s) on the console window, and return a flag whether all the zone(s) were 
  75. valid.
  76.  
  77.     WARNING!    Do not put DumpBlocks inside the memory routines!  The 
  78.                 console I/O routines also make use of malloc and free, and 
  79.                 can cause havoc with the memory zones!
  80.  
  81.     WARNING!    These memory routines have been tested, but not to the 
  82.                 thoroughness we require for released software.  If you have 
  83.                 problems with this code, please send mail to 
  84.                 SYMGlenn@devtools.symantec.com so that any bugs can be 
  85.                 squashed.
  86.  
  87. Release Notes
  88. -------------
  89.  
  90. Release 1.0.10
  91. -------------
  92. * Added functionality for big blocks to automatically get returned to
  93.   the application zone, regardless of the setting of gRestoreMemToHeap.
  94. * When allocating memory, I check to see if the existing zone(s) could
  95.   satisfy the request before checking if the size is greater than the
  96.   crossover size.
  97.  
  98. Release 1.0.9
  99. -------------
  100. * I missed yet one more assignment in 1.0.8 when the next block isn't
  101.   a free block when freeing.
  102.  
  103. Release 1.0.8
  104. -------------
  105. * I missed an assignment in 1.0.7 when fixing the bug in free where, if the
  106.   next block was the end of zone, it wasn't setting the size correctly for
  107.   the newly freed block.
  108. * I now provide an AppleScript to update the ANSI libraries for both TPM and
  109.   SPM to use alloc_gla.c instead of alloc.c.
  110.  
  111. Release 1.0.7
  112. -------------
  113. * There was a bug in free when the block that was being freed was the last
  114.   block in a zone.  It wasn't getting combined with the previous block if
  115.   the previous block was also a free block. (thanks DF)
  116.  
  117. Release 1.0.6
  118. -------------
  119. * Commented out the _UseAssert_ and _Debug_Alloc_GLA__ macros, since they
  120.   shouldn't have been uncommented in the final version.
  121.  
  122. Release 1.0.5
  123. -------------
  124. * Bug fixed in alloc when the block is getting initialized.  It was allocating
  125.   space for a block of the specified size, but was initializing for a maximum
  126.   block size of sizeof(MemBlock) bytes smaller.
  127. * Bug fixed in calculating the 8 byte size (alignment). It was adding 8, which
  128.   could allocate 8 bytes more than was necessary, if the requested size was
  129.   already a multiple of 8.
  130.  
  131. Release 1.0.4
  132. -------------
  133. * Bug fixed in realloc when the block following this block was the end
  134.   of the zone, which is a special "free" block.  Now special casing for
  135.   end of zone.
  136. * Bug fixed in realloc when the block following this block was free, but
  137.   wasn't large enough to satisfy the request for the resize.  Now mallocs
  138.   a new block if this is the case.
  139. * Made sure all asserts were inside conditional compile flag.
  140. * Added CheckBlocks routine for testing allocations without I/O.
  141. * Sizes are now a multiple of 8, which means that addresses should also
  142.   be a multiple of 8.  This will improve performance on PowerPC with
  143.   doubles.
  144.  
  145. Release 1.0.3
  146. -------------
  147. * Improved realloc performance when the next block is a free block since
  148.   realloc will now manipulate the free block size rather than moving the
  149.   current block if it is growing.
  150. * Fixed many annoying bugs in realloc when the new size would make the
  151.   size of the following free block smaller than 2 bytes.
  152.  
  153. Release 1.0.2
  154. -------------
  155. * Fixed problems with blocks larger than gMaxBlockSize.  They were still
  156.   marked as free blocks, even though they were in use.
  157.   
  158. Release 1.0.1
  159. -------------
  160. * Fixed problems with splitting a free block when the first free block
  161.   would be close to the same size as the block being split.  The second
  162.   block header would overwrite the beginne next block header.
  163.  
  164. Release 1.0
  165. -----------
  166. * Initial release on Symantec C++ 8.0 CD